package version

import (
	"fmt"
	"go-fiber-ip2region/global"
	"go-fiber-ip2region/model/version/response"
	"io/ioutil"
	"os"
)

type VersionService struct{}

//@function: GetVersionInfo
//@description: 获取版本详情
//@return: verInfo VersionInfoRes, err error
func (v *VersionService) GetVersionInfo() (verInfo response.VersionInfoRes, err error) {

	var changelog []byte

	changelog, err = getChangelog()

	verInfo = response.VersionInfoRes{Version: global.GLOBAL_CONFIG.VERSION, BuildAt: global.GLOBAL_CONFIG.BUILD_AT, Changelog: string(changelog)}

	return verInfo, err
}

func getChangelog() (changelog []byte, err error) {
	var f *os.File
	f, err = os.Open("./CHANGELOG.md")

	if err != nil {
		fmt.Println("open changelog err:" + err.Error())
	}
	defer f.Close()

	changelog, err = ioutil.ReadAll(f)

	return changelog, err
}
